{include file='_header'}
<div class="page-header">
   当前位置：<span class="text-primary"> 提现申请信息
        <small>(申请单号: {$item['applyno']}</small>
        <small>商家信息: {$item['realname']} {$item['mobile']})</small></span>
</div>
<div class="page-content">
    <div class="step-region" >
        <ul class="ui-step ui-step-4" >
            <li {if $item['status']>=1}class="ui-step-done"{/if}>
                <div class="ui-step-number" >1</div>
                <div class="ui-step-title" >申请中</div>
                <div class="ui-step-meta" >{if 1<=$item['status']}{:date('Y-m-d',$item['applytime'])}<br/>{:date('H:i:s',$item['applytime'])}{/if}</div>
            </li>
            <li  {if $item['status']>=2}class="ui-step-done"{/if}>
                <div class="ui-step-number">2</div>
                <div class="ui-step-title">商家审核</div>
                <div class="ui-step-meta">{if 2<=$item['status']}{:date('Y-m-d',$item['checktime'])}<br/>{:date('H:i:s',$item['checktime'])}{/if}</div>
            </li>
            <li {if $item['status']>=3}class="ui-step-done"{/if}>
                <div class="ui-step-number" >3</div>
                <div class="ui-step-title">商家打款</div>
                <div class="ui-step-meta" >{if 3<=$item['status']}{:date('Y-m-d',$item['paytime'])}<br/>{:date('H:i:s',$item['paytime'])}{/if}</div>
            </li>
            <li {if $item['status']==-1}class="ui-step-done"{/if}>
                <div class="ui-step-number" >!</div>
                <div class="ui-step-title">无效</div>
                <div class="ui-step-meta" >{if -1==$item['status']}{:date('Y-m-d',$item['invalidtime'])}<br/>{:date('H:i:s',$item['invalidtime'])}{/if}</div>
            </li>
        </ul>
    </div>
    {include file='merch/check/box'}
    <form action="" method="get" class="form-horizontal " role="form" id="form1">
        <input type="hidden" name="id" value="{$id}"/>
        <input type="hidden" name="status" value="{$status}"/>
        <div class="page-toolbar m-b-sm m-t-sm">
            {include file='merch/check/applytype'}
            <div class="col-sm-6 pull-right">
                <div class="input-group">
                    <input type="text" class="form-control input-sm" name="keyword" value="{$_GPC['keyword']}" placeholder="订单编号"/>
                 <span class="input-group-btn">
                    <button class="btn btn-primary" type="submit"> 搜索</button>
                    <button type="submit" name="export" value="1" class="btn btn-success">导出</button>
                </span>
                </div>
            </div>
        </div>
    </form>
    {include file='merch/check/table'}
    <div class="form-group">
        <div class="text-left">
            {if $item['status']==1}
                <input type="button" id="btnconfirm" value="通过申请" class="btn btn-success"/>
                <input type="button" id="btnnoconfirm" value="拒绝所有申请" class="btn btn-warning"/>
            {/if}
            {if $item['status']==2}
                <div class="page-toolbar m-b-sm m-t-sm">
                    <div class="col-sm-7" style="width: 320px;">
                        <div class="input-group">
                            <input type="text" class="form-control input-sm" id="finalprice" name="finalprice" value="{$item['passrealpricerate']}" placeholder="打款金额"/>
                            <span class="input-group-btn">
                             {if $item['applytype']==0 || $item['applytype']==2}
                            <button class="btn btn-sm btn-danger" id="btnpay" type="button" style="margin-left: 20px;"> 确认打款</button>
                            {/if}
                            <button class="btn btn-sm btn-warning" id="btnpayhand" type="button" style="margin-left: 20px;">手动处理</button>
                            </span>
                        </div>
                    </div>
                </div>
            {/if}
        </div>
    </div>
</div>

<script>
    window.partners = [];
    window.current = 0;
    $(function () {
        $('.checkall').click(function () {
            var checked = $(this).prop('checked');
            $('.checkitem').prop('checked', checked);
        });
        $('#btnnoconfirm').click(function () {
            tip.confirm('确认要拒绝所有申请？',function(){
                confirm(-1);
            });
        });
        $('#btnconfirm').click(function () {
            if ($('.checkitem:checked').length<=0) {
                tip.msgbox.err('请选择通过申请的订单!');
                return;
            }
            $('.checkitem:checked').each(function(){
                window.partners.push( $(this).val() );
            });
            tip.confirm('通过申请后无法进行修改，确认吗？',function(){
                confirm(1);
            });
        });

        $('#btnpay').click(function () {
            if ($('#finalprice').isEmpty()) {
                tip.msgbox.err('请输入打款金额!');
                return;
            }
            var finalprice = $('#finalprice').val();
            var msg = '确认要打款' + finalprice + '元吗？';
            tip.confirm(msg,function(){
                $('#btnpay').button('loading');
                $.ajax({
                    url: "{:url('admin/merch/checkmerchpay')}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: "{$item['id']}", 'finalprice': finalprice, 'handpay': 0
                    },
                    success: function (ret) {
                        $('#btnpay').button('reset');
                        var result = ret.result;
                        if (ret.status != 1) {
                            tip.msgbox.err(result.message);
                            return;
                        }
                        location.href = biz.url("merch.check.status{$status}");
                    }
                });
            });
        });
        $('#btnpayhand').click(function () {
            if ($('#finalprice').isEmpty()) {
                tip.msgbox.err('请输入打款金额!');
                return;
            }
            var applytype = $('#applytype').val();
            var msg = '手动处理 , 系统不进行任何打款操作!<br/>请确认你已通过线下方式为商户打款!!!<br/>是否进行手动处理?';
            var finalprice = $('#finalprice').val();
            tip.confirm(msg,function(){
                $('#btnpayhand').button('loading');
                $.ajax({
                    url: "{:url('admin/merch/checkmerchpay')}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: "{$item['id']}", 'finalprice': finalprice, 'handpay': 1
                    },
                    success: function (ret) {
                        $('#btnpayhand').button('reset');
                        var result = ret.result;
                        if (ret.status != 1) {
                            tip.msgbox.err(result.message);
                            return;
                        }
                        location.href = biz.url("merch.check.status{$status}");
                    }
                });
            });
        });
    });
    function confirm(type){
        if (type == 1) {
            $('#btnconfirm').button('loading');
        } else {
            $('#btnnoconfirm').button('loading');
        }
        $.ajax({
            url: "{:url('admin/merch/checkconfirm')}",
            type: 'post',
            dataType: 'json',
            data: {
                id: "{$item['id']}", 'type': type, 'bpid': window.partners
            },
            success: function (ret) {
                if (type == 1) {
                    $('#btnconfirm').button('reset');
                } else {
                    $('#btnnoconfirm').button('reset');
                }
                var result = ret.result;
                if (ret.status != 1) {
                    tip.msgbox.err(result.message);
                    return;
                }
                location.href = biz.url("merch.check.status{$status}");
            }
        });
    }
</script>
{include file='_footer'}